package com.mytijian.task.model;

public class TaskIdentify {
    private final static String split = "_";
    private String groupKey;
    /**
     * key
     */
    private Integer taskId;
    private Integer beginSubTaskId;
    private Integer endSubTaskId;

    private TaskIdentify() {

    }
    public TaskIdentify(String groupKey, Integer taskId, Integer beginSubTaskId, Integer endSubTaskId) {
        this.groupKey = groupKey;
        this.taskId = taskId;
        this.beginSubTaskId = beginSubTaskId;
        this.endSubTaskId = endSubTaskId;
    }

    public Integer getTaskId() {
        return taskId;
    }

    public Integer getBeginSubTaskId() {
        return beginSubTaskId;
    }

    public Integer getEndSubTaskId() {
        return endSubTaskId;
    }

    public String getGroupKey() {
        return groupKey;
    }


    @Override
    public String toString() {
        return getTaskKey();
    }

    public static TaskIdentify build(String identifyString) {
        String[] strings = identifyString.split(split);
        return new TaskIdentify(strings[0],
                Integer.parseInt(strings[1]),
                Integer.parseInt(strings[2]),
                Integer.parseInt(strings[3]));
    }
    public String getTaskKey() {
        StringBuilder builder = new StringBuilder();
        builder.append(this.getGroupKey());
        builder.append(split);
        builder.append(this.getTaskId());
        builder.append(split);
        builder.append(this.getBeginSubTaskId());
        builder.append(split);
        builder.append(this.getEndSubTaskId());
        return builder.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        TaskIdentify that = (TaskIdentify) o;

        if (getTaskId() != null ? !getTaskId().equals(that.getTaskId()) : that.getTaskId() != null) return false;
        if (getBeginSubTaskId() != null ? !getBeginSubTaskId().equals(that.getBeginSubTaskId()) : that.getBeginSubTaskId() != null)
            return false;
        return getEndSubTaskId() != null ? getEndSubTaskId().equals(that.getEndSubTaskId()) : that.getEndSubTaskId() == null;
    }

    @Override
    public int hashCode() {
        int result = getTaskId() != null ? getTaskId().hashCode() : 0;
        result = 31 * result + (getBeginSubTaskId() != null ? getBeginSubTaskId().hashCode() : 0);
        result = 31 * result + (getEndSubTaskId() != null ? getEndSubTaskId().hashCode() : 0);
        return result;
    }
}
